﻿using System;

namespace DynamicVm.Wpf
{
    class DelegateCommand : DelegateCommandBase
    {
        public override bool CanExecute(object parameter)
        {
            return _canExecute == null || _canExecute();
        }

        public override void Execute(object parameter)
        {
            _execute();
        }

        public DelegateCommand(Action execute, Func<bool> canExecute = null)
        {
            Contract.NotNull(execute, "execute");
            _execute = execute;
            _canExecute = canExecute;
        }

        private readonly Action _execute;
        private readonly Func<bool> _canExecute;
    }
}
